package com.czl.module_storehouse.adapter;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.czl.base.data.bean.tengyun.ReceiveBean;
import com.czl.module_storehouse.R;
import com.lihang.ShadowLayout;

/**
 * @author by xubin,
 * @date on 2022/1/25.
 * PS: Not easy to write code, please indicate.
 */
public class ReceiveHomeAdapter extends BaseQuickAdapter<ReceiveBean, BaseViewHolder> {

    private boolean visible;

    public ReceiveHomeAdapter(int layoutResId) {
        super(layoutResId);
    }

    public boolean isVisible() {
        return visible;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, ReceiveBean item) {
        baseViewHolder.setText(R.id.tv_title, item.getReceiveName())
                .setText(R.id.tv_date, item.getApplyDate())
                .setText(R.id.tv_code, "领用单：" + (item.getReceiveCode() == null ? "" : item.getReceiveCode()))
                .setText(R.id.tv_department, "领用部门：" + (item.getReceiveOrganizationName() == null
                        ? item.getReceivePersonDepartment() == null ? "" : item.getReceivePersonDepartment()
                        : item.getReceiveOrganizationName()))
                .setText(R.id.tv_desc, "领用说明：" + (item.getNote() == null
                        ? item.getApplyComment() == null ? "" : item.getApplyComment()
                        : item.getNote()))
                .setGone(R.id.tv_receive_total, item.isVisibleNum(visible))
                .setText(R.id.tv_receive_total, item.getReceiveTotalTextNum("已领"));

        ShadowLayout shadowLayout = baseViewHolder.getView(R.id.shadowLayout);
        shadowLayout.setShadowHiddenTop(baseViewHolder.getLayoutPosition() != 0);
        baseViewHolder.getView(R.id.tv_receive_total).setOnClickListener(v -> {
            if (getOnItemChildClickListener() != null) {
                getOnItemChildClickListener().onItemChildClick(ReceiveHomeAdapter.this, v, baseViewHolder.getLayoutPosition());
            }
        });
        baseViewHolder.getView(R.id.cl_root).setOnClickListener(v -> {
            if (getOnItemChildClickListener() != null) {
                getOnItemChildClickListener().onItemChildClick(ReceiveHomeAdapter.this, v, baseViewHolder.getLayoutPosition());
            }
        });

    }
}
